import { getSearchAjax, getSearchHotAjax } from "@/http/modules/search";
const { createSlice, createAsyncThunk } = require("@reduxjs/toolkit");

export const getSearchInfo = createAsyncThunk("search",async (msg)=>{
    const res = await getSearchAjax(msg);
    return res.result.songs
})

export const getSearchHotInfo = createAsyncThunk("searchHot",async ()=>{
    const res = await getSearchHotAjax();
    return res.data
})


const searchSlice = createSlice({
    name:"search",
    initialState:{
        searchData:[],
        searchHot:[]
    },
    extraReducers:{
        [getSearchInfo.fulfilled](state,{payload}){
            state.searchData = payload;
        },
        [getSearchHotInfo.fulfilled](state,{payload}){
            state.searchHot = payload
        }
    }
})

export default searchSlice.reducer